/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_tongeasy.c                                        */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/24 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include "../../src/module/tongeasy/config.h"
#include "t_te_comm/t_te_comm.h"
#include "t_te_core/t_te_core.h"
#include "t_te_packet/t_te_packet.h"
#include "t_te_header/t_te_header.h"

#include <frservice_mng.h>

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    // t_te_comm
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_free);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_frtime2datetimestr);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_bin_to_hex_string);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_packet_is_in_fragment);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_report_msg_data_req);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_report_msg_data_resp);

    // t_te_header
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_header_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_header_unpack);

    // t_te_packet
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_init_packet);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_pkt_is_fragmented);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_packet_check_fragment);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_packet_unfragment);

    // t_te_core
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_private_session_init);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_detect);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_destroy_packet);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__te_destroy_stmt);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_session_destroy);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_te_analyze);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();

    fr_slab_destroy();

    return 0;
}
